<html>
<head>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseUrl();?>/css/manager.css" />
<script type="text/javascript" src="<?php echo $this->baseUrl();?>/js/jquery-1.7.min.js"></script>
<script type="text/javascript" src="<?php echo $this->baseUrl();?>/js/jquery.validate.js"></script>
<script type="text/javascript">

//Validate cho form add user
	 $(document).ready(function (){
	    $('#form_AddUser').validate();
	 });

	 function ShowConfirmDeleteUser(id)
	 {
		 //alert("<?php echo $this->baseUrl('admin/user/delete/id/');?>");
		 if (confirm("Bạn có chắc chắn muốn xóa xóa User này không ?"))
		 {
		 	window.location = "<?php echo $this->baseUrl('admin/user/delete/id/');?>" + id;
		 }
		 else
		 {
		 }
	 }

 /*function ConfirmAddData()
 {
	 var username = (document.form_AddUser.txt_Username).value;
     var password = (document.form_AddUser.txt_Password).value;
     var email = (document.form_AddUser.txt_Email).value;
     var decentralize = (document.form_AddUser.list_Decentralize).value;
     var fullname = (document.form_AddUser.txt_Fullname).value;
     //alert(username);
     if(username=''){
        alert(username);
     }else{
        window.location = "./delete/";
     }
	 
 }*/
</script>
</head>

<body>
<div id="wrapper">
    <form id="form_AddUser" name="form_AddUser" method="post" action="">
        <label for="username"><strong>Username :<span>*</span></strong></label> 
        <input type="text" size="50" name="txt_Username" id="txt_Username" class="required" />
        
        <label for="password"><strong>Password :<span>*</span></strong></label>
        <input type="password" size="50" name="txt_Password" id="txt_Password" class="required" />
        
        <label for="decentralize"><strong>Decentralize :</strong></label>
        <select name="list_Decentralize" id="list_Decentralize">
          <option value="User">User</option>
          <option value="Administrator">Administrator</option>
          <option value="Mod">Mod</option>
        </select>
        
        <label for="email"><strong>Email :<span>*</span></strong></label>
        <input type="text" size="50" name="txt_Email" id="txt_Email" class="required" />
        
        <label for="fullname"><strong>Full Name :<span>*</span></strong></label>
        <input type="text" size="50" name="txt_Fullname" id="txt_Fullname" class="required" />
        
        <input type="submit" name="btn_Add" id="btn_Add" value="Add" />
    </form>
</div>

<?php
if ($this->resultAdd == FALSE) {
	echo "</br>Add failed.";
} else {
	echo "</br>Add successfully.";
	//$this->_redirect($this->baseUrl('./admin/user/manager/'));
}
$this->resultAdd = "";
?>

<div id="managerUsers">
	<form id="managerUsers" name="managerUsers" method="" action="">
		<table width="100%" border="1">
			<tr>
				<td><b>ID</b></td>
                <td><b>Username</b></td>
                <td><b>Password</b></td>
                <td><b>Decentralize</b></td>
                <td><b>Email</b></td>
                <td><b>Full Name</b></td>
                <td><b>Status</b></td>
                <td><b>Action</b></td>
			</tr>
            
            <?php 
			foreach ($this->users as $user){
				echo '<tr>';
			
				echo	"<td>{$user['id']}</td>";
				echo	"<td>{$user['username']}</td>";
				echo	"<td>{$user['password']}</td>";
				echo	"<td>{$user['decentralize']}</td>";
				echo	"<td>{$user['email']}</td>";
				echo	"<td>{$user['full_name']}</td>";
				echo	"<td>{$user['status']}</td>";
				echo "<td><a href= '".$this->baseUrl('./admin/user/edit/id/').$user['id']."'>Edit</a>";
				echo "<input type=\"button\" name=\"delete\" 
				id=\"{$user['id']}\" value=\"Delete\" onclick=\"ShowConfirmDeleteUser({$user['id']})\"> </td>";
				//<a href='./delete/id/{$user['id']}'>Delete</a>
				echo "";				
				echo '</tr>';
			}
			?>
			
		</table>
	</form>
</div>

</body>
</html>
